function _mergesort(arr, start, end, temp) {
    if(start >= end) return
    let middle = Math.floor((start + end) / 2)
    _mergesort(arr, start, middle, temp)
    _mergesort(arr, middle + 1, end, temp)
    let start1 = start, end1 = middle
    let start2 = middle + 1, end2 = end
    let index = start
    while(start1 <= end1 && start2 <= end2) {
        if(arr[start1] < arr[start2]) {
            temp[index++] = arr[start1]
            start1++
        } else {
            temp[index++] = arr[start2]
            start2++
        }
    }
    while(start1 <= end1) {
        temp[index++] = arr[start1++]
    }
    while(start2 <= end2) {
        temp[index++] = arr[start2++]
    }
    for(let i = start; i <= end; i++) {
        arr[i] = temp[i]
    }
}
let arr = [9, 8, 4, 7, 5, 3, 6]
let temp = new Array(arr.length)
_mergesort(arr, 0, arr.length - 1, temp)
console.log(arr);